// page/sell/sell.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    show: '',
    smallPrice: '0', //总计和小计
    teamName: '', //项目名称
    sellType: '洗车单',
    totalPrice: '0', //总计
    idx:'',
    items: [{
        id: '0',
        name: '普洗-轿车',
        price: '35',
        checked: 'true'
      },
      {
        id: '1',
        name: '普洗-越野车',
        price: '36',
        checked: 'false'
      },
      {
        id: '2',
        name: '精细-娇车',
        price: '37',
        checked: 'false'
      },
      {
        id: '3',
        name: '精细-娇车',
        price: '37',
        checked: 'false'
      },
      {
        id: '4',
        name: '精细-娇车',
        price: '37',
        checked: 'false'
      },
      {
        id: '5',
        name: '精细-越野车',
        price: '38',
        checked: 'false'
      }
    ],
    obj: [{
        id: '0',
        name: '轿车',
        type: '套餐一',
        price: '100',
        show: true,
        team: [{
          teamName: '达拉',
          teamPrice: '48',
        }]
      },
      {
        id: '1',
        name: '越野车',
        type: '套餐二',
        price: '200',
        show: false,

        team: [{
          teamName: '达拉',
          teamPrice: '90'
        }, {
          teamName: '洗车',
          teamPrice: '200',
        }]
      },
      {
        id: '2',
        name: '娇车',
        type: '套餐三',
        price: '300',
        show: true,

        team: [{
          teamName: '达拉',
          teamPrice: '70',
        }]
      },
      {
        id: '3',
        name: '娇车',
        type: '套餐四',
        price: '400'
      }
    ],
    date: {
      date: '2019-01-01 13:37',
      startDate: '2019-01-01 12:37',
      endDate: '2019-03-12 12:38',
      placeholder: '请选择时间',
    },
    date1: {
      date: '2019-01-01 13:37',
      startDate: '2019-01-01 12:37',
      endDate: '2019-03-12 12:38',
      placeholder: '请选择时间',
    },
    modalShow: false
  },
  //选取业务类型
  sellType() {
    var list = ['预检单', '洗车单', '维保单', '销售单'];
    var _this = this
    wx.showActionSheet({
      itemList: list,
      success(res) {
        console.log(list[res.tapIndex])
        _this.setData({
          sellType: list[res.tapIndex],
          colorBool: false
        })
      },
      fail(res) {
        console.log(res.errMsg)
      }
    })
  },
  // 时间选取
  onPickerChange(e) {
    this.setData({
      date: e.detail.dateString
    })
    console.log(this.data.date)
  },
  onPickerChange1(e) {
    this.setData({
      date1: e.detail.dateString
    })
    console.log(this.data.date1)
  },
  cancel() {
    this.setData({
      modalShow: false
    })
  },
  //项目的单选按钮
  radioChange(e) {
    console.log(e.detail.value)
    this.setData({
      idx:e.detail.value
    })
  },
  //点击项目的确定按钮
  determine() {
    let idx=this.data.idx
    let items = this.data.items;
    let list=this.data.list
    list.push({
      price: items[idx].price,
      name: items[idx].name
    })
    this.setData({
      list: list,
      modalShow:false
    })
  },
  // 点击删除
  delete(e){
    console.log(e.currentTarget.dataset.id)
    let id=e.currentTarget.dataset.id
    let list=this.data.list
    list.splice(id,1)
    this.setData({
      list:list
    })
  },
  //是否显示套餐的具体内容
  mealShow(e) {
    console.log(e.currentTarget.dataset.id)
    let obj = this.data.obj
    let index = e.currentTarget.dataset.id
    if (obj[index].show == true) {
      obj[index].show = false
    } else {
      obj[index].show = true
    }
    this.setData({
      obj: obj
    })
  },
  // 套餐的确定按钮
  mealDeter(e) {
    console.log(e)
    this.setData({
      totalPrice: this.data.transPrice,
      modalShow: false
    })
  },
  // 套餐的单选框
  radioMeal(e) {
    console.log(e.detail.value)
  },
  isPlayingMusic() {
    this.setData({
      modalShow: false
    })
  },
  //获取备注的内容
  getContent(e) {
    console.log(e.detail.value)
  },
  
// 弹窗的显示
  showMedal(e){
    this.setData({
      show: e.currentTarget.dataset.id,
      modalShow: true
    })
  }
})